import { http } from "@/utils/http";
import { ProjectQuery, ProjectRequest, ProjectVO } from "@/types/attendance/project";
import { ResponseData } from "@/types/common/response";

/**
 * 获取项目列表（用于下拉框）
 * @returns 项目列表
 */
export function getProjectList(): Promise<ResponseData<ProjectVO[]>> {
  return http.get<any, ResponseData<ProjectVO[]>>("/attendance/project/list");
}

/**
 * 获取项目详情
 */
export function getProjectDetail(projectId: number) {
  return http.get<any, Common.ResponseData<ProjectVO>>(`/attendance/project/${projectId}`);
}

/**
 * 新增项目
 */
export function addProject(data: ProjectRequest) {
  return http.post("/attendance/project", { data });
}

/**
 * 修改项目
 */
export function updateProject(data: ProjectRequest) {
  return http.request("put", "/attendance/project", { data });
}

/**
 * 删除项目
 */
export function deleteProject(projectId: number) {
  return http.request("delete", `/attendance/project/${projectId}`);
}

/**
 * 更新项目状态
 */
export function updateProjectStatus(projectId: number, status: string) {
  return http.request("put", `/attendance/project/status/${projectId}`, {
    data: { status }
  });
}

/**
 * 获取项目成员列表
 */
export function getProjectMembers(projectId: number) {
  return http.get(`/attendance/project/${projectId}/members`);
}

/**
 * 添加项目成员
 */
export function addProjectMember(projectId: number, data: { personnelIds: number[] }) {
  return http.post(`/attendance/project/${projectId}/members`, { data });
}

/**
 * 移除项目成员
 */
export function removeProjectMember(projectId: number, personnelId: number) {
  return http.request("delete", `/attendance/project/${projectId}/members/${personnelId}`);
}

/**
 * 导出项目数据
 */
export function exportProject(query: ProjectQuery) {
  return http.download("/attendance/project/export", "项目列表.xlsx", {
    params: query
  });
}

/**
 * 下载导入模板
 */
export function downloadImportTemplate() {
  return http.get("/attendance/project/importTemplate", {
    responseType: "blob"
  });
}

/**
 * 获取项目统计数据
 */
export function getProjectStats(projectId: number) {
  return http.get(`/attendance/project/${projectId}/stats`);
}

/**
 * 更新项目进度
 */
export function updateProjectProgress(projectId: number, progress: number) {
  return http.request("put", `/attendance/project/${projectId}/progress`, {
    data: { progress }
  });
}

/**
 * 批量删除项目
 */
export function batchDeleteProjects(projectIds: number[]) {
  return http.request("delete", "/attendance/project/batch", {
    data: { projectIds }
  });
}

/**
 * 获取项目选项列表（专用于下拉框）
 * @returns 项目选项列表
 */
export function getProjectOptions(): Promise<ResponseData<any[]>> {
  return http.get<any, ResponseData<any[]>>("/attendance/project/options");
}
